package TripleInOne;

public class Solution {
    class TripleInOne {
        int[] arr;
        int[] size = new int[3];
        int stackSize;
        public TripleInOne(int stackSize) {
            this.stackSize = stackSize;
            arr = new int[stackSize*3];
        }

        public void push(int stackNum, int value) {
            // 添加元素
            if(size[stackNum]<stackSize) {
                arr[stackNum*stackSize + size[stackNum]] = value;
                size[stackNum]++;
            }
        }

        public int pop(int stackNum) {
            // 弹出最后一个元素
            if ( isEmpty(stackNum) ) {
                return -1;
            }
            return arr[stackNum*stackSize+(--size[stackNum])];
        }

        public int peek(int stackNum) {
            if( isEmpty(stackNum) ) {
                return -1;
            }
            return arr[stackNum*stackSize+size[stackNum]-1];
        }
        public boolean isEmpty(int stackNum) {
            return size[stackNum] == 0;
        }
    }
}
